/*
	Produces Figures 2 and 3, along with the underlying regression tables
*/

// SET DIRECTORIES
cd ""

	use data_study1.dta, clear
	

	gen harris0 = 0
	label var harris0 "Control"
	gen duck0 = 0
	label var duck0 "Control"
	
	loc clrnat "gs0"
	loc clrasn "gs6"
	loc clramr "gs8"
	label var tr_asian "Asian"
	label var tr_indian "Indian"
	label var tr_black "Black"
	label var tr_multi "Asian/Black"
	label var tr_duckt "Thai/Asian"
	label var tr_duckc "Control"

	loc reglist_harris "tr_asian tr_indian tr_black tr_multi harris0"
	loc reglist_duck  "tr_duckt duck0"
	loc reglist_full "tr_asian tr_indian tr_black tr_multi harris0 tr_duckt tr_duckc"
	
	loc colazn = "gs0"
	loc colnon = "gs8"
	
	
//*------------------------- Harris Main Results -----------------------*//	
	// Effect of Prime on Perceived Asianness
	eststo clear
	
	reg rate_harris `reglist_harris' if harris == 1 & race == "Asian", robust
	eststo rate_harris_a
	outreg2 using table_fig23a.xls, replace dec(3) ctitle("Harris Asian-ness, Asians")
	
	// Effect of Prime on Representation
	foreach p in repasam repblack repmy repmycomm favor {
		reg harris_`p' `reglist_harris' if harris == 1 & race == "Asian", robust
		eststo `p'_a
		outreg2 using table_fig23a.xls, append dec(3) ctitle("Harris `p', Asians")
	}
		
	foreach v in rate_harris favor repasam repblack repmy repmycomm { 
	
		if "`v'" == "rate_harris" loc name "(a) Harris Asian-ness"
		if "`v'" == "favor" loc name = "(b) Harris Favorability" 
		if "`v'" == "repasam" loc name = "(a) Represents Asian Americans" 
		if "`v'" == "repblack" loc name = "(b) Represents Black Americans" 
		if "`v'" == "repmy" loc name = "(c) Represents me" 
		if "`v'" == "repmycomm" loc name = "(d) Represents my community" 
		
		if "`v'" == "repasam" loc tit "title("Kamala Harris", span)"
		if "`v'" != "repasam" loc tit "title("Kamala Harris", span color(white))"
		if inlist("`v'", "rate_harris", "favor") loc tit ""
		
	
		coefplot (`v'_a, mc(`colazn') ms(c) ciopts(lw(medthick) color(`colazn'))) ///
			, drop(_cons) msize(medlarge) legend(off) ///
			omitted baselevels xline(0, lc(black)) xlabel(-.3(.1).3) ///
			subtitle("{bf:`name'}", bcolor(white) color(black) size(small) box pos(12) ///
				bmargin(small) bexpand margin(small)) `tit' ///
			ytitle("Candidate Identity Primes", size(small)) ylabel(, labsize(small)) ///
			norecycle saving(fig_`v'.gph, replace)
	}	
	
	
//*------------------------- Duckworth Results -----------------------*//
		eststo clear
		
		reg rate_duckworth `reglist_duck' if duck == 1 & race == "Asian", robust
		eststo rate_duck_a
		outreg2 using table_fig23b.xls, replace dec(3) ctitle("Duck Asian-ness, Asians")
		
		foreach p in repasam repblack repmy repmycomm favor {
	
			reg duckworth_`p' `reglist_duck' if duck == 1 & race == "Asian", robust
			eststo `p'_duck_a
			outreg2 using table_fig23b.xls, append dec(3) ctitle("Duck `p', Asians")
			
		}
	
		foreach v in rate repasam repblack repmy repmycomm favor { 
		
			if "`v'" == "rate" loc name "(c) Duckworth Asian-ness"
			if "`v'" == "favor" loc name = "(d) Duckworth Favorability" 
			if "`v'" == "repasam" loc name = "(e) Represents Asian Americans" 
			if "`v'" == "repblack" loc name = "(f) Represents Black Americans" 
			if "`v'" == "repmy" loc name = "(g) Represents me" 
			if "`v'" == "repmycomm" loc name = "(h) Represents my community" 
			
			if "`v'" == "repasam" loc tit "title("Tammy Duckworth", span)"
			if "`v'" != "repasam" loc tit "title("Tammy Duckworth", span color(white))"
			if inlist("`v'", "rate", "favor") loc tit ""
			
			coefplot (`v'_duck_a, mc(`colazn') ms(c) ciopts(lw(medthick) color(`colazn'))) ///
				, drop(_cons) msize(medlarge) legend(off) ///
				omitted baselevels xline(0, lc(black)) xlabel(-.3(.1).3) ///
				subtitle("{bf:`name'}", bcolor(white) color(black) size(small) box pos(12) ///
					bmargin(small) bexpand margin(small)) `tit' ///
				ytitle("Candidate Identity Primes", size(small)) ylabel(, labsize(small)) ///
				norecycle saving(fig_`v'_duck.gph, replace)
		}	

// Create combined figures
	graph combine fig_rate_harris.gph fig_favor.gph ///
		fig_rate_duck.gph fig_favor_duck.gph
	graph export Figure2.png, as(png) replace

	graph combine fig_repasam.gph fig_repblack.gph fig_repmy.gph fig_repmycomm.gph ///
		fig_repasam_duck.gph fig_repblack_duck.gph fig_repmy_duck.gph fig_repmycomm_duck.gph, rows(2) 
	graph display, xsize(5.5) ysize(3)
	graph export Figure3.png, as(png) replace



// Clean up extra files
fs *.txt *.gph
foreach f in `r(files)' {
	erase `f'
}

exit


	
